import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';

// 扩展 dayjs 插件
dayjs.extend(relativeTime);

/**
 * 时间工具函数
 */
export function useTimeUtils() {
  const formatDate = (date: Date | string, format = 'YYYY-MM-DD HH:mm:ss') => {
    return dayjs(date).format(format);
  };

  const getRelativeTime = (date: Date | string) => {
    return dayjs(date).fromNow();
  };

  const getCurrentTime = () => {
    return dayjs().format('YYYY-MM-DD HH:mm:ss');
  };

  return {
    formatDate,
    getRelativeTime,
    getCurrentTime,
  };
}
